#include"string.h"

void test01()
{
    String s("11111");
    cout << s.c_str() << endl;

    String s1(3, 'a');
    cout << s1.c_str() << endl;

    String s2 = s;
    cout << s2.c_str() << endl;

    for(int i = 0; i < s.size(); i++)
        cout << s[i] << ' ';
    cout << endl;

    for(auto e : s) cout << e << ' ';
    cout << endl;

    const String s3 = "1234567";
    auto i = s3.begin();
    while(i != s3.end())
    {
        cout << *i << ' ';
        i++;
    }
    cout << endl;
    for(int i = 0; i < s3.size(); i++) 
        cout << s3[i];
    cout << endl;
}


void test02()
{
    String s1;
    s1 += "Hello";
    cout << s1.c_str() << endl;

    s1 += ' ';
    cout << s1.c_str() << endl;

    s1 += "C++";
    cout << s1.c_str() << endl;

    String s2 = "密密麻麻";
    s1 += s2;
    cout << s1.c_str() << endl;
}

void test03()
{
    String s1 = "abcdefg";
    s1.insert(0, "ijklmn");
    cout << s1.c_str() << endl;
    
    s1.erase(3);
    cout << s1.c_str() << endl;

    String s2 = "Hello C++";
    s2.insert(9, "x");
    cout << s2.c_str() << endl;
}

void test04()
{
    String s = "ababa";
    int i = s.find("aba");
    while(i != -1)
    {
        cout << i << " ";
        i = s.find("aba", i + 1);
    }
}

void test05()
{
    String s = "ababa";
    String s1 = {100, 'x'};
    s = s1;
    s[0] = 'a';
    cout << s.c_str() << endl;
    cout << s1.c_str() << endl;
}

void test06()
{
    String url = "https://editor.csdn.net/md/?articleId=151691236&spm=1011.2415.3001.9698";
    int p1 = url.find(':');
    cout << url.substr(0, p1).c_str() << endl;

    int p2 = url.find('/', p1 + 3);
    cout << url.substr(p1 + 3, p2 - (p1 + 3)).c_str() << endl;
    cout << url.substr(p2 + 1).c_str() << endl;
}

void test07()
{
    String s;
    cin >> s;
    cout << s;
}
int main()
{
    // test07();
    // char s[10] = "";

    // String s;
    String s = "xxxx";
    String s1(s);
    // printf("%p\n", s.c_str());
    // printf("%p\n", s1.c_str());
    // Linux写时拷贝

    cout << s.find("x", 4) << endl;
    return 0;
}

